package org.codehaus.jackson.map.ser;

import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.introspect.Annotated;
import org.codehaus.jackson.map.introspect.BasicBeanDescription;
import org.codehaus.jackson.map.util.Annotations;
import org.codehaus.jackson.type.JavaType;

/* loaded from: classes2.dex */
public class PropertyBuilder {
    protected final AnnotationIntrospector _annotationIntrospector;
    protected final BasicBeanDescription _beanDesc;
    protected final SerializationConfig _config;
    protected Object _defaultBean;
    protected final JsonSerialize.Inclusion _outputProps;

    public PropertyBuilder(SerializationConfig serializationConfig, BasicBeanDescription basicBeanDescription) {
        this._config = serializationConfig;
        this._beanDesc = basicBeanDescription;
        this._outputProps = basicBeanDescription.findSerializationInclusion(serializationConfig.getSerializationInclusion());
        this._annotationIntrospector = serializationConfig.getAnnotationIntrospector();
    }

    public Annotations getClassAnnotations() {
        return this._beanDesc.getClassAnnotations();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x008d, code lost:
        if (r2 != 4) goto L45;
     */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00e0  */
    /* JADX WARN: Removed duplicated region for block: B:49:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public org.codehaus.jackson.map.ser.BeanPropertyWriter buildWriter(java.lang.String r16, org.codehaus.jackson.type.JavaType r17, org.codehaus.jackson.map.JsonSerializer<java.lang.Object> r18, org.codehaus.jackson.map.TypeSerializer r19, org.codehaus.jackson.map.TypeSerializer r20, org.codehaus.jackson.map.introspect.AnnotatedMember r21, boolean r22) {
        /*
            Method dump skipped, instructions count: 235
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: org.codehaus.jackson.map.ser.PropertyBuilder.buildWriter(java.lang.String, org.codehaus.jackson.type.JavaType, org.codehaus.jackson.map.JsonSerializer, org.codehaus.jackson.map.TypeSerializer, org.codehaus.jackson.map.TypeSerializer, org.codehaus.jackson.map.introspect.AnnotatedMember, boolean):org.codehaus.jackson.map.ser.BeanPropertyWriter");
    }

    /* renamed from: org.codehaus.jackson.map.ser.PropertyBuilder$1  reason: invalid class name */
    /* loaded from: classes2.dex */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$org$codehaus$jackson$map$annotate$JsonSerialize$Inclusion;

        static {
            int[] iArr = new int[JsonSerialize.Inclusion.values().length];
            $SwitchMap$org$codehaus$jackson$map$annotate$JsonSerialize$Inclusion = iArr;
            try {
                iArr[JsonSerialize.Inclusion.NON_DEFAULT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$org$codehaus$jackson$map$annotate$JsonSerialize$Inclusion[JsonSerialize.Inclusion.NON_EMPTY.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$org$codehaus$jackson$map$annotate$JsonSerialize$Inclusion[JsonSerialize.Inclusion.NON_NULL.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$org$codehaus$jackson$map$annotate$JsonSerialize$Inclusion[JsonSerialize.Inclusion.ALWAYS.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
        }
    }

    protected JavaType findSerializationType(Annotated annotated, boolean z, JavaType javaType) {
        JsonSerialize.Typing findSerializationTyping;
        JavaType constructSpecializedType;
        Class<?> findSerializationType = this._annotationIntrospector.findSerializationType(annotated);
        if (findSerializationType != null) {
            Class<?> rawClass = javaType.getRawClass();
            if (findSerializationType.isAssignableFrom(rawClass)) {
                constructSpecializedType = javaType.widenBy(findSerializationType);
            } else if (!rawClass.isAssignableFrom(findSerializationType)) {
                throw new IllegalArgumentException("Illegal concrete-type annotation for method '" + annotated.getName() + "': class " + findSerializationType.getName() + " not a super-type of (declared) class " + rawClass.getName());
            } else {
                constructSpecializedType = this._config.constructSpecializedType(javaType, findSerializationType);
            }
            javaType = constructSpecializedType;
            z = true;
        }
        JavaType modifySecondaryTypesByAnnotation = BeanSerializerFactory.modifySecondaryTypesByAnnotation(this._config, annotated, javaType);
        if (modifySecondaryTypesByAnnotation != javaType) {
            javaType = modifySecondaryTypesByAnnotation;
            z = true;
        }
        if (!z && (findSerializationTyping = this._annotationIntrospector.findSerializationTyping(annotated)) != null) {
            z = findSerializationTyping == JsonSerialize.Typing.STATIC;
        }
        if (z) {
            return javaType;
        }
        return null;
    }

    protected Object getDefaultBean() {
        if (this._defaultBean == null) {
            Object instantiateBean = this._beanDesc.instantiateBean(this._config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS));
            this._defaultBean = instantiateBean;
            if (instantiateBean == null) {
                Class<?> annotated = this._beanDesc.getClassInfo().getAnnotated();
                throw new IllegalArgumentException("Class " + annotated.getName() + " has no default constructor; can not instantiate default bean value to support 'properties=JsonSerialize.Inclusion.NON_DEFAULT' annotation");
            }
        }
        return this._defaultBean;
    }

    protected Object getDefaultValue(String str, Method method, Field field) {
        Object defaultBean = getDefaultBean();
        try {
            if (method != null) {
                return method.invoke(defaultBean, new Object[0]);
            }
            return field.get(defaultBean);
        } catch (Exception e) {
            return _throwWrapped(e, str, defaultBean);
        }
    }

    protected Object getContainerValueChecker(String str, JavaType javaType) {
        if (this._config.isEnabled(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS)) {
            return null;
        }
        if (javaType.isArrayType()) {
            return new EmptyArrayChecker();
        }
        if (Collection.class.isAssignableFrom(javaType.getRawClass())) {
            return new EmptyCollectionChecker();
        }
        return null;
    }

    protected Object getEmptyValueChecker(String str, JavaType javaType) {
        Class<?> rawClass = javaType.getRawClass();
        if (rawClass == String.class) {
            return new EmptyStringChecker();
        }
        if (javaType.isArrayType()) {
            return new EmptyArrayChecker();
        }
        if (Collection.class.isAssignableFrom(rawClass)) {
            return new EmptyCollectionChecker();
        }
        if (Map.class.isAssignableFrom(rawClass)) {
            return new EmptyMapChecker();
        }
        return null;
    }

    /* JADX WARN: Code restructure failed: missing block: B:0:?, code lost:
        r3 = r3;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    protected java.lang.Object _throwWrapped(java.lang.Exception r3, java.lang.String r4, java.lang.Object r5) {
        /*
            r2 = this;
        L0:
            java.lang.Throwable r0 = r3.getCause()
            if (r0 == 0) goto Lb
            java.lang.Throwable r3 = r3.getCause()
            goto L0
        Lb:
            boolean r0 = r3 instanceof java.lang.Error
            if (r0 != 0) goto L42
            boolean r0 = r3 instanceof java.lang.RuntimeException
            if (r0 == 0) goto L16
            java.lang.RuntimeException r3 = (java.lang.RuntimeException) r3
            throw r3
        L16:
            java.lang.IllegalArgumentException r3 = new java.lang.IllegalArgumentException
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            r0.<init>()
            java.lang.String r1 = "Failed to get property '"
            r0.append(r1)
            r0.append(r4)
            java.lang.String r4 = "' of default "
            r0.append(r4)
            java.lang.Class r4 = r5.getClass()
            java.lang.String r4 = r4.getName()
            r0.append(r4)
            java.lang.String r4 = " instance"
            r0.append(r4)
            java.lang.String r4 = r0.toString()
            r3.<init>(r4)
            throw r3
        L42:
            java.lang.Error r3 = (java.lang.Error) r3
            goto L46
        L45:
            throw r3
        L46:
            goto L45
        */
        throw new UnsupportedOperationException("Method not decompiled: org.codehaus.jackson.map.ser.PropertyBuilder._throwWrapped(java.lang.Exception, java.lang.String, java.lang.Object):java.lang.Object");
    }

    /* loaded from: classes2.dex */
    public static class EmptyCollectionChecker {
        public boolean equals(Object obj) {
            return obj == null || ((Collection) obj).size() == 0;
        }
    }

    /* loaded from: classes2.dex */
    public static class EmptyMapChecker {
        public boolean equals(Object obj) {
            return obj == null || ((Map) obj).size() == 0;
        }
    }

    /* loaded from: classes2.dex */
    public static class EmptyArrayChecker {
        public boolean equals(Object obj) {
            return obj == null || Array.getLength(obj) == 0;
        }
    }

    /* loaded from: classes2.dex */
    public static class EmptyStringChecker {
        public boolean equals(Object obj) {
            return obj == null || ((String) obj).length() == 0;
        }
    }
}
